package com.metadata_system.common.db.mapper;

import com.metadata_system.common.db.entity.Message;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface MessageMapper extends Mapper<Message> {
    /**
     * 统计用户未读消息数量
     * @param userId 用户ID
     * @return 包含两种未读数量的Map
     */
    @Select("SELECT " +
            "COUNT(*) as count " +
            "FROM md_message " +
            "WHERE user_id = #{userId} AND is_read = 0 AND type='ProjectUser' ")
    Integer countUnReadMessage(@Param("userId") Integer userId);

    @Update("UPDATE md_message SET is_read = 1 WHERE user_id = #{userId}")
    void readAll(@Param("userId") Integer userId);
}